package com.twinkle.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.twinkle.dao.PreviewDataResultMapper;
import com.twinkle.model.PreviewDataResult;
import com.twinkle.model.PreviewDataResultUI;
import com.twinkle.service.PreviewDataResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @title: PreviewDataResultServiceImpl
 * @description:
 * @author: Paul
 * @date: 2023/3/16 15:43
 */
@Service
public class PreviewDataResultServiceImpl implements PreviewDataResultService {
    @Autowired
    PreviewDataResultMapper previewDataResultMapper;

    @Override
    public PreviewDataResultUI getPreviewDataResultByModelId(String modelId) {

        PreviewDataResultUI previewDataResultUI = new PreviewDataResultUI();
        PreviewDataResult previewDataResult = previewDataResultMapper.selectOne(new QueryWrapper<PreviewDataResult>().eq("model_id", modelId));
        previewDataResultUI.setInfo(previewDataResult.getInfo());
        previewDataResultUI.setDescrib(previewDataResult.getDescrib());
        List<JSONObject> modelData = JSONArray.parseArray(previewDataResult.getModelData(), JSONObject.class);
        previewDataResultUI.setModelData(modelData);
        return previewDataResultUI;
    }
}
